package com.javasm.mingming.adminuser.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javasm.mingming.adminuser.service.AdminAuthorityService;
import com.javasm.mingming.adminuser.service.AdminRoleService;
import com.javasm.mingming.adminuser.dao.AdminUserDao;
import com.javasm.mingming.adminuser.entity.AdminAuthority;
import com.javasm.mingming.adminuser.entity.AdminRole;
import com.javasm.mingming.adminuser.entity.AdminUser;
import com.javasm.mingming.adminuser.service.AdminUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 后台用户(AdminUser)表服务实现类
 *
 * @author makejava
 * @since 2025-01-11 09:51:34
 */
@Service("adminUserService")
public class AdminUserServiceImpl extends ServiceImpl<AdminUserDao, AdminUser> implements AdminUserService {

    @Resource
    AdminRoleService roleService;
    @Resource
    AdminAuthorityService authorityService;




    @Override
    public AdminUser getByUname(String username) {
        LambdaQueryWrapper<AdminUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AdminUser::getUsername,username);
        AdminUser adminUser = getOne(queryWrapper);
        if (adminUser != null){
            //根据 rid 查询 角色信息
            AdminRole adminRole = roleService.getByRid(adminUser.getRoleId());
            adminUser.setAdminRole(adminRole);
            //查询 权限列表
            List<AdminAuthority> authorityList = authorityService.getByUid(adminUser.getUid());
            adminUser.setAuthorityList(authorityList);
        }
        return adminUser;
    }
    @Override
    public AdminUser getByPhone(String phone) {
        LambdaQueryWrapper<AdminUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AdminUser::getPhone,phone);
        AdminUser adminUser = getOne(queryWrapper);
        return adminUser;
    }

    @Override
    public AdminUser getByUid(String uid) {
        AdminUser adminUser = getById(Long.parseLong(uid));
        return adminUser;
    }
}

